//验证手机号
export const validateMobile = (rule, value, callback) => {
    var reg = /^1\d{10}$/;
    if (!reg.test(value)) {
        callback(new Error("手机号格式错误"));
    } else {
        callback();
    }
};



//验证必填项
export const validateRequired = (rule, value, callback) => {
    var reg = /[\S]+/;
    if (!reg.test(value)) {
        callback(new Error("必填项不能为空"));
    } else {
        callback();
    }
};



//验证邮箱格式
export const validateEmail = (rule, value, callback) => {
    var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!reg.test(value)) {
        callback(new Error("邮箱格式不正确"));
    } else {
        callback();
    }
};



//验证链接格式
export const validateUrl = (rule, value, callback) => {
    var reg = /(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/;
    if (!reg.test(value)) {
        callback(new Error("链接格式不正确"));
    } else {
        callback();
    }
};



//验证链日期格式
export const validateDate = (rule, value, callback) => {
    var reg = /^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/;
    if (!reg.test(value)) {
        callback(new Error("日期格式不正确"));
    } else {
        callback();
    }
};




//验证字符串长度
export const validateNumberLen10 = (rule, value, callback) => {
    var reg = /^.{10}$/;
    if (!reg.test(value)) {
        callback(new Error("字符串长度不能超过10"));
    } else {
        callback();
    }
};



//验证数字
export const validateNumber = (rule, value, callback) => {
    var reg = /^[0-9]*$/;
    if (!reg.test(value)) {
        callback(new Error("请输入数字"));
    } else {
        callback();
    }
};

